    # = test.forum.14.rb - Forum , Reply to Forum Post Test 
    # See LICENSE.txt for licensing details.
    #
    # == Description
    # Here we the following functionalities are tested  a) Disable duplicate flooding  
    #                                                                      b) Reply functionality under Sample Forum Post
    #                                                                      c) Delete a Post Reply
    #
    require 'watir'
    include Watir
    require 'test/unit'
    require 'watir/WindowHelper'
    require '../watir.config.rb'
    require '../resources/functions.rb'
    
	class TC_ReplyToForumPost_test < Test::Unit::TestCase
    
    def startup
      $PostTags = randomChar(10)
      $PostReplyTag = randomChar(5)
      $PostReplyBody = randomChar(20)
      $PostBody = randomChar(50)
      
      
      @@ie = Watir::IE.start($SITE_URL)
	  end
	
	  def ie
      if defined? @@ie
        @@ie
      else
        startup
      end
	  end
    
    def test_01_verifyHomeText
      assert(ie.contains_text(/Community Server/))		
	  end
  
    def test_02_verifyLoginLinksExist
      if !(ie.link(:text, 'Sign in').exists?)
        ie.goto($SITE_URL + 'logout.aspx')
        ie.refresh
        ie.goto($SITE_URL)
        ie.refresh
      end
	  end
    
    def test_03_navigateToLogin
      ie.link(:text, 'Sign in').click
      assert(ie.contains_text("Sign in name"))
    end
	  
	  def test_04_populateLoginForm
      ie.text_field(:id, /username$/).value = $ADMIN_USER
      assert(ie.text_field(:id, /username$/).verify_contains($ADMIN_USER))
      
      ie.text_field(:id, /password$/).value = $ADMIN_PASSWORD
      assert(ie.text_field(:id, /password$/).verify_contains($ADMIN_PASSWORD))
	  end
	  
    def test_05_submitLoginForm
      ie.link(:id, /loginButton$/).click
      test_01_verifyHomeText
    end

    def test_06_verifyLogoutLinkExists
      assert_equal $SITE_URL + 'logout.aspx', ie.link(:text, 'Sign out').href
    end
    
    def test_07_disableDuplicationPostCheck
      assert(ie.link(:text, /Control Panel/).exists?)
      ie.link(:text, /Control Panel/).click
      ie.link(:text, /Administration/).click
      ie.cell(:text, "Forums").click
      ie.link(:text, "Global Forum Settings").click
      ie.cell(:text, "Duplicates & Flooding").click
      ie.radio(:id, /.AllowDuplicatePosts_0/).set
      ie.link(:text, "Save").click
      ie.link(:text, "Exit Control Panel and Return to Site").click
    end
    
    def test_07_navigateToForum
      assert_equal $SITE_URL +'forums/', ie.link(:text, 'Forums').href
      ie.link(:text, 'Forums').click
      assert(ie.link(:text, /Sample Forum$/).exists?)
      ie.link(:text, /Sample Forum$/).click
    end
    
    def test_08_navigateToForumPost
      assert(ie.link(:text, "New Post").exists?)
      ie.link(:text, "New Post").click
      assert(ie.contains_text("New Post"))
    end
    
    def test_09_verifyForumButtonsExist
      assert(ie.link(:text, "Reply").exists?)
      assert(ie.link(:text, "Delete").exists?)
      assert(ie.link(:text, "Edit").exists?)
      assert(ie.link(:text, "Favorites").exists?)
      assert(ie.link(:text, "Contact").exists?)
      assert(ie.link(:text, "Moderate").exists?)
      assert(ie.link(:text, "Previous").exists?)
      assert(ie.link(:text, "Next").exists?)
      assert(ie.link(:text, "Reply").exists?)
      assert(ie.link(:text, "Change View").exists?)
    end
    
    def test_10_verifyReplyLinkWorks
      ie.link(:text, "Reply").click
      assert(ie.text_field(:id, /PostSubject$/).exists?)
      assert(ie.text_field(:id, /PostSubject$/).verify_contains("Re: New Post"))
    end
  
    def test_11_testTextFieldsExistAndEnabled
      assert(ie.text_field(:id, /PostSubject$/).exists?)
      assert(ie.text_field(:id, /Editor$/).exists?)
      assert(ie.text_field(:id, /Tags$/).exists?)
      
      assert(ie.text_field(:id, /PostSubject$/).enabled?)
      assert(ie.text_field(:id, /Editor$/).enabled?)
      assert(ie.text_field(:id, /Tags$/).enabled?)
    end
    
    
    def test_12_enterReplyAndSubmit
      ie.ie.Document.parentWindow.execScript("tinyMCE.getInstanceById(tinyMCE.getEditorId('mce_editor_0')).execCommand('mceSetContent', false, '" + $PostReplyBody + "')")
      #ie.ie.Document.parentWindow.execScript("tinyMCE.getInstanceById(tinyMCE.getEditorId('mce_editor_0')).execCommand('mceSetContent', false, '" + $PostReplyBody + "')")
      ie.text_field(:id, /Tags$/).set($PostReplyTag)
      
      assert(ie.button(:id, /PostButton$/).exists?)
      ie.button(:id, /PostButton$/).click
    end
  
    def test_13_deletePostReply
      assert(ie.link(:text, "Delete").exists?)
      ie.link(:text, "Delete").click
      sleep 3
      
      assert(ie.contains_text("You are about to delete the following post:"))
      assert(ie.text_field(:id, /DeleteReason$/).exists?)
      ie.text_field(:id, /DeleteReason$/).set("Just testing the forum using watir")
      sleep 5
      assert(ie.text_field(:id, /DeleteReason$/).verify_contains("Just testing the forum using watir"))
      
      assert(ie.button(:id, /DeletePost$/).exists?)
      
      startClicker("OK" , 2)      
      ie.button(:id, /DeletePost$/).click      
      sleep 5
    end
    
    def test_15_confirmPostDeleted      
      assert_equal(false, ie.link(:text, "New Post").exists?)
    end
    
    def test_16_createSampleForumPost
      assert(ie.link(:text, "Write a New Post").exists?)
      ie.link(:text, "Write a New Post").click
      sleep 5
      ie.text_field(:id, /PostSubject$/).set("New Post")
      ie.ie.Document.parentWindow.execScript("tinyMCE.getInstanceById(tinyMCE.getEditorId('mce_editor_1')).execCommand('mceSetContent', false, 'Sample Forum Post Body')")
      sleep 5
      ie.button(:id, /PostButton$/).click
    end
      
  end